<?php
/* [$WindsForce] (C)Hunzhiwange.COM Since 2012.03.17.
   家居商家点评控制器($小牛New $2014.07.28)*/

!defined('Q_PATH') && exit;

class JiajucompanycommentController extends AController{

	public function init__(){
		$this->_arrNotMethod=array(
			'save_previewstatus',
			'save_preview',
			'view_preview',
			'foreverdelete_deep',
			'input_change_ajax',
			'input_change_unique',
			'forbid',
			'closeitem',
			'openitem',
			'resume',
			'clear_recycle',
			'save_sort',
			'insert',
			'add',
			'edit',
			'update'
		);
		
		parent::init__();
	}
	
	public function filter_(&$arrMap){
		$arrMap['A.jiajucompanycomment_content']=array('like',"%".Q::G('jiajucompanycomment_content')."%");
		$arrMap['A.jiajucompanycomment_name']=array('like',"%".Q::G('jiajucompanycomment_name')."%");
		$arrMap['A.jiajucompanycomment_replycontent']=array('like',"%".Q::G('jiajucompanycomment_replycontent')."%");
		$arrMap['A.jiajucompany_id']=$GLOBALS['_company_']['jiajucompany_id'];
		
		// 添加时间
		$this->getTime_('A.create_dateline',$arrMap);

		$nJiajucompanycommentLevel=Q::G('jiajucompanycomment_level');
		if($nJiajucompanycommentLevel!==null && $nJiajucompanycommentLevel!=''){
			$arrMap['A.jiajucompanycomment_level']=$nJiajucompanycommentLevel;
		}
	}

	public function reply(){
		$nCommentId=intval(Q::G('id'));
		if(empty($nCommentId)){
			exit('未指定回复的点评ID');
		}

		$arrWhere=array();
		$arrWhere['jiajucompany_id']=$GLOBALS['_company_']['jiajucompany_id'];
		$arrWhere['jiajucompanycomment_status']=array('neq',9);
		$arrWhere['jiajucompanycomment_id']=$nCommentId;

		$oJiajucompanycomment=JiajucompanycommentModel::F()->where($arrWhere)->getOne();
		if(empty($oJiajucompanycomment['jiajucompanycomment_id'])){
			exit('待回复的点评不存在');
		}

		// 保存点评回复
		if($this->isPost()){
			$oJiajucompanycomment->jiajucompanycomment_replyusername=$GLOBALS['___login___']['user_name'];
			$oJiajucompanycomment->jiajucompanycomment_replyuserid=$GLOBALS['___login___']['user_id'];
			$oJiajucompanycomment->jiajucompanycomment_replytime=CURRENT_TIMESTAMP;
			$oJiajucompanycomment->save('update');
			if($oJiajucompanycomment->isError()){
				$this->E($oJiajucompanycomment->getErrorMessage());
			}else{
				$arrData=array(
					'comment_id'=>$oJiajucompanycomment['jiajucompanycomment_id'],
					'user_name'=>$GLOBALS['___login___']['user_name'],
					'reply_content'=>Core_Extend::ubb(Q::G('jiajucompanycomment_replycontent'),false),
					'reply_time'=>date('Y-m-d H:i',CURRENT_TIMESTAMP),
				);

				if(!Q::classExists('Jiaju_Credit')){
					require_once(WINDSFORCE_PATH.'/System/app/jiaju/App/Class/Extension/Jiaju_Credit.class.php');
				}
				Jiaju_Credit::RUN($GLOBALS['_company_']['jiajucompany_id'],$nCommentId,$oJiajucompanycomment->create_dateline,1,0,'','jiajucompanycommentreply');
				
				$this->A($arrData,'点评回复成功',1);
			}
		}

		$this->assign('oJiajucompanycomment',$oJiajucompanycomment);
		$this->display();
	}

}
